#include "ICPLabel.h"

#include "ICPNode.h"
#include "SchDuty.h"
#include "SchPairing.h"

int ICPLabel::_countId = 0;

ICPLabel::ICPLabel(ICPNode* node, SchDuty* prevDuty, double profit, ICPLabel* prevLabel, int deadheadCnt,
                   set<BasAirport*> nightAirports)
    : _node(node), _prevDuty(prevDuty), _profit(profit), _prevLabel(prevLabel), _deadheadCnt(deadheadCnt),
      _nightAirports(nightAirports) {
    _id = _countId++;
}

ICPLabel::~ICPLabel() {}

bool ICPLabel::dominate(ICPLabel* label) {
    if (_prevDuty->getDate() != label->getPrevDuty()->getDate()) {
        cout << "Error label dominate!" << endl;
        exit(0);
    }
    if (ICPUtility::dominateMode == DOMINATE_MODE::MULTI) {
        if (this->getDeadheadCnt() > label->getDeadheadCnt()) {
            return false;
        }
        if (this->getNightAirports().size() > label->getNightAirports().size()) {
            return false;
        }
        if (this->getPrevDuty()->getType() != DUTY_REST && label->getPrevDuty()->getType() != DUTY_REST) {
            if (this->getPrevDuty()->getSta() <= label->getPrevDuty()->getSta() &&
                this->getProfit() >= label->getProfit()) {
                return true;
            }
        } else if (this->getProfit() >= label->getProfit()) {
            return true;
        }
    } else {
        if (this->getPrevDuty()->getType() != DUTY_REST && label->getPrevDuty()->getType() != DUTY_REST) {
            if (this->getProfit() >= label->getProfit()) {
                return true;
            }
        }
    }

    return false;
}

void ICPLabel::print() {
    cout << "* label-> id-" << _id;
    cout << " node-" << _node->getId();
    cout << " profit: " << _profit;
    cout << "\tprevDuty: ";
    if (_prevDuty != NULL) {
        _prevDuty->print();
    } else {
        cout << " NULL " << endl;
    }
    //	_prevDuty->print();
}
